home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection 1998 Fall: Game Toolkit / Disc.iso / SDKs / Apple Game Sprockets / InputSprocket / Sample Drivers / Common Driver Code / Common.h next >
Encoding:
C/C++ Source or Header  |  1998-07-17  |  4.3 KB  |  158 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************
  2.  
  3. File:      Common.h
  4.  
  5. Copyright © 1996, 1997, 1998 Apple Computer, Inc., All Rights Reserved
  6.  
  7.  
  8. You may incorporate this sample code into your applications without
  9. restriction, though the sample code has been provided "AS IS" and the
  10. responsibility for its operation is 100% yours.  However, what you are
  11. not permitted to do is to redistribute the source as "DSC Sample Code"
  12. after having made changes. If you're going to re-distribute the source,
  13. we require that you make it clear in the source that the code was
  14. descended from Apple Sample Code, but that you've made changes.
  15.  
  16. *************************************************************************************/
  17.  
  18. #ifndef __COMMON__
  19. #define __COMMON__
  20.  
  21. #include <stdlib.h>
  22.  
  23. #ifndef __MEMORY__
  24. #include <Memory.h>
  25. #endif
  26.  
  27. #ifndef __MACTYPES__
  28. #include <MacTypes.h>
  29. #endif
  30.  
  31. #ifndef __RESOURCES__
  32. #include <Resources.h>
  33. #endif
  34.  
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38.  
  39.  
  40. /*
  41.  *    Debugging flags -- should be set by prefix file or command line
  42.  */
  43.  
  44. #ifndef DEBUG_NOISY
  45.     #define DEBUG_NOISY            0
  46. #endif
  47.  
  48. #ifndef DEBUG
  49.     #if DEBUG_NOISY
  50.         #define DEBUG            1
  51.     #else
  52.         #define DEBUG            0
  53.     #endif
  54. #endif
  55.  
  56.  
  57. /*
  58.  *    Validation
  59.  *        CHECK(int test, int err) is used with a non-void (typically OSStatus) return type.
  60.  *        CHECK_RETURN(int test) is used with a void return type.
  61.  */
  62.  
  63. #if DEBUG_NOISY
  64.     #define FAIL_IF(cond, handler)    {if((cond)){DebugStr("\pCHECK(" #cond ") failed in " __FILE__ " at " DEBUG_STR(__LINE__)); goto handler;}}
  65.     #define DEBUG_CODE(e)        e
  66.     #define DEBUG_STR(x)        DEBUG_VAL(x)
  67.     #define DEBUG_VAL(x)        #x
  68.     #define CHECK(test,err)        {if(!(test)){DebugStr("\pCHECK(" #test ", " #err ") failed in " __FILE__ " at " DEBUG_STR(__LINE__)); return (err);}}
  69.     #define CHECK_RETURN(test)    {if(!(test)){DebugStr("\pCHECK_RETURN(" #test ") failed in " __FILE__ " at " DEBUG_STR(__LINE__)); return;}}
  70.     #define NAG(test,str,err)    {if(!(test)){DebugStr("\p" #str ); return (err);}}
  71.     #define NAG_RETURN(test,str)    {if(!(test)){DebugStr("\p" #str ); return;}}
  72.     #define WARNING(test, str)    {if(!(test)){DebugStr("\p" #str);}}
  73.     #define RES_WARNING(str)    { if (ResError()) {DebugStr("\p" #str);}}
  74.     #define QD_WARNING(str)        { if (QDError()) {DebugStr("\p" #str);}}
  75. #elif DEBUG
  76.     #define FAIL_IF(cond, handler)    {if((cond)){DebugStr("\pCHECK(" #cond ") failed in " __FILE__ " at " DEBUG_STR(__LINE__)); goto handler;}}
  77.     #define DEBUG_CODE(e)        e
  78.     #define CHECK(test,err)        {if(!(test))return (err);}
  79.     #define CHECK_RETURN(test)    ((void)0)
  80.     #define NAG(test,str,err)    {if(!(test))return (err);}
  81.     #define NAG_RETURN(test,str)    {if(!(test))return;}
  82.     #define WARNING(test, str)    ((void)0)
  83.     #define RES_WARNING(str)        ((void)0)
  84.     #define QD_WARNING(str)        ((void)0)
  85. #else
  86.     #define FAIL_IF(cond, handler)    {goto handler;}
  87.     #define DEBUG_CODE(e)        ((void)0)
  88.     #define CHECK(test,err)        ((void)0)
  89.     #define CHECK_RETURN(test)    ((void)0)
  90.     #define NAG(test,str,err)    ((void)0)
  91.     #define NAG_RETURN(test,str)    ((void)0)
  92.     #define WARNING(test, str)    ((void)0)
  93.     #define RES_WARNING(str)        ((void)0)
  94.     #define QD_WARNING(str)        ((void)0)
  95. #endif
  96.  
  97.  
  98. /*
  99.  *    Thumbprints
  100.  */
  101.  
  102. typedef enum Thumbprint {
  103.     kThumbprintDead            = 'dead',        /* Not a valid object                        */
  104.     kThumbprintListener        = 'lsnr',        /* A sound Listener, subclass of Spatial    */
  105.     kThumbprintSource        = 'ssrc'        /* A sound Source, subclass of Spatial        */
  106. } Thumbprint;
  107.  
  108.  
  109. /*
  110.  *    Memory management
  111.  */
  112.  
  113. #define HandleAlloc(size)        NewHandle(size)
  114. #define HandleFree(p)            DisposeHandle(p)
  115. #define HandleResize(p,size)    SetHandleSize(p,size)
  116. #define HandleLock(p)            HLock((Handle)p)
  117. #define HandleUnlock(p)            HUnlock((Handle)p)
  118.  
  119. #define SysHandleAlloc(size)    NewHandleSys(size)
  120. #define SysHandleFree(p)        DisposeHandle(p)
  121. #define SysHandleResize(p,size)    SetHandleSize(p,size)
  122. #define SysHandleLock(p)        HLock(p)
  123. #define SysHandleUnlock(p)        HUnlock(p)
  124.  
  125.  
  126. void* SysHandleRealloc(
  127.     void*                p,
  128.     UInt32                size);
  129.  
  130. #define PtrAlloc(size)            NewPtr(size)
  131. #define PtrFree(p)                DisposePtr(p)
  132.  
  133. void* PtrRealloc(
  134.     void*                p,
  135.     UInt32                size);
  136.  
  137. #define SysPtrAlloc(size)        NewPtrSys(size)
  138. #define SysPtrFree(p)            DisposePtr(p)
  139.  
  140. void* SysPtrRealloc(
  141.     void*                p,
  142.     UInt32                size);
  143.  
  144.  
  145.  
  146. /*
  147.  *    Pascal string fun
  148.  */
  149.  
  150. //    Removed because it's kinda bogus jwo 10/21
  151. //#define CopyPascalString(dst,src)    BlockMove(src,dst,(src)[0]+1)
  152.  
  153. #ifdef __cplusplus
  154. }
  155. #endif
  156.  
  157. #endif /* __COMMON__ */
  158.